﻿// Global variables
USETEXTLINKS = 1;
indexOfEntries = new Array;
nEntries = 0;
doc = document;
browserVersion = 0;
selectedFolder = 0;
selectedLink = '';

function Folder(folderDescription, hreference, folderOpenImg, folderCloseImg, folderKey) {

   //constant data;
   this.desc = folderDescription;
   this.hreference = hreference;
   this.id = -1;
   this.key = folderKey;
   this.navObj = 0;
   this.iconImg = 0;
   this.nodeImg = 0;
   this.folderImg = 0;
   this.isLastNode = 0;
   this.isRoot = true;
   this.isOpen = true;
   this.iconSrc = folderOpenImg;
   this.iconRoot = folderCloseImg;
   this.children = new Array;
   this.nChildren = 0;
   this.selectedFolder = false;
   this.isFolder = true;

   // methods
   this.initialize = initializeFolder;
   this.setState = setStateFolder;
   this.addChild = addChild;
   this.createIndex = createEntryIndex;
   this.hide = hideFolder;
   this.display = display;
   this.renderOb = drawFolder;
   this.totalHeight = totalHeight;
   this.subEntries = folderSubEntries;
   this.outputLink = outputFolderLink;
}

function setStateFolder(isOpen) {
   var subEntries;
   var totalHeight;
   var fIt = 0;
   var i = 0;
   if(isOpen == this.isOpen)
       return;

   if(browserVersion == 2) {
       totalHeight = 0
       for(i = 0; i < this.nChildren; i++)
           totalHeight = totalHeight + this.children[i].navObj.clip.height;
       subEntries = this.subEntries();

       if(this.isOpen)
           totalHeight = 0 - totalHeight;
       for(fIt = this.id + subEntries + 1; fIt < nEntries; fIt++)
           indexOfEntries[fIt].navObj.moveBy(0, totalHeight);
   }
   this.isOpen = isOpen;
   propagateChangesInState(this);
}

function propagateChangesInState(folder) {

   var i = 0;
   if(folder.isOpen) {
       if(folder.nodeImg) {
           if(folder.isLastNode)
               folder.nodeImg.src = "/resource/images/left_ball01.gif";
           else
               folder.nodeImg.src = "/resource/images/left_ball01.gif";
       }

       if(this.isRoot)
           folder.iconImg.src = "/elms/common/img/mail.gif";
       else {
           folder.iconImg.src = folder.iconSrc;
		}

       for(i = 0; i < folder.nChildren; i++)
           folder.children[i].display();
   }
   else {
       if(folder.nodeImg) {
           if(folder.isLastNode)
               folder.nodeImg.src = "/resource/images/left_ball01.gif";
           else
               folder.nodeImg.src = "/resource/images/left_ball01.gif";
       }

       if(this.isRoot)
           folder.iconImg.src = "/elms/common/img/mail.gif";
       else
           folder.iconImg.src = folder.iconRoot;

       for(i = 0; i < folder.nChildren; i++)
           folder.children[i].hide();
   }
}

function hideFolder() {
    if(browserVersion == 1) {
        if(this.navObj.style.display == "none")
            return;

        this.navObj.style.display = "none";
    }
    else {
        if(this.navObj.visibility == "hiden")
            return;

        this.navObj.visibility = "hiden";
    }
    this.setState(0);
}

function initializeFolder(level, lastNode, leftSide) {

    var i = 0;
    var j = 0;

    var numberOfFolders;
    var numberOfDocs;

    nc = this.nChildren;
    this.createIndex();

    var nc;
    var auxEv = "";

    if(browserVersion > 0)
        auxEv = "<A HREF='JavaScript: clickOnNode("+this.id+")'>";
    else
        auxEv = "<A>";

    if(level > 0) {
	   this.renderOb(leftSide + auxEv + "<IMG NAME='nodeIcon" + this.id + "' SRC='/resource/images/left_ball01.gif' class='leftmenu_ball01' BORDER=0></A>");
	   this.isLastNode = 1;
    }
    else {
        this.renderOb("");
    }

    if(nc > 0) {
        level = level + 1;
        for(i = 0; i < this.nChildren; i++) {
            if(i == this.nChildren-1)
                this.children[i].initialize(level, 1, leftSide);
            else
                this.children[i].initialize(level, 0, leftSide);
        }
    }
}



// 폴더 생성 //
function drawFolder(leftSide) {
    if(browserVersion == 2) {
        if(!doc.yPos)
          doc.yPos = 8;
        doc.write("<LAYER ID='folder" + this.id + "' TOP=" + doc.yPos + " VISIBILITY=hiden>");
    }

	doc.write("<TABLE")

	if(browserVersion == 1) {
		doc.write(" ID='folder" + this.id + "' STYLE='position:block;' ");
	}

	// 첫 메뉴 이미지
	if( this.id != 0) {

		doc.write(" width='166' border='0' cellspacing='0' cellpadding='0' style='margin:0 0 0 7'>");
		doc.write("<tr><td colspan='3' class='leftmenu_line'></td></tr>");
		doc.write("<TR><TD width='151' CLASS='leftmenu2dep'>");
		doc.write(leftSide);

		if(leftSide == '') {
		   if(USETEXTLINKS) {
			  this.outputLink();
			  doc.write(this.desc + "</A>");
		   }
		   else {
			 doc.write(this.desc);
		   }
		}
		else {
			if( this.id != 0) {
				doc.write("<A HREF='JavaScript: clickOnNode("+this.id+")' >");
				doc.write(this.desc + "</A>");
			}
		}

		doc.write("</TD>");

		doc.write("<TD align='right'>");
		doc.write("<A HREF='JavaScript: clickOnNode("+this.id+")' >");
		doc.write("<IMG NAME='folderIcon" + this.id + "' ");
		if(leftSide == '') {
			doc.write("SRC='/resource/images/" + this.iconRoot + "' BORDER=0></A>");
		}
		else {
			doc.write("SRC='/resource/images/" + this.iconSrc + "' BORDER=0></A>");
		}

		doc.write("</TD>");
		doc.write("</TR>");
	}
	else {
		doc.write(" border='0' cellspacing='0' cellpadding='0'>");

		doc.write("<TR><TD width='151' CLASS='leftmenu2dep'>");
		doc.write(leftSide);

		doc.write("<IMG NAME='folderIcon" + this.id + "' ");
		if(leftSide == '') {
			doc.write("SRC='/resource/images/" + this.iconRoot + "' BORDER=0></A>");
		}
		else {
			doc.write("SRC='/resource/images/" + this.iconSrc + "' BORDER=0></A>");
		}
		doc.write("</TD>");
		doc.write("</TR>");

		doc.write("<TR height='10'><TD></TD></TR>");
	}

	doc.write("</TABLE>");

    if(browserVersion == 2) {
        doc.write("</LAYER>");
    }

	// 선택된 폴더 지정 //
	if (this.selectedFolder)
	{
		selectedFolder = this.id;
	}

    if(browserVersion == 1) {
        this.navObj = doc.all["folder"+this.id];
        this.iconImg = doc.all["folderIcon"+this.id]
        this.nodeImg = doc.all["nodeIcon"+this.id]
		this.folderImg = doc.all["folderImg"+this.id]
    }

    else if(browserVersion == 2) {
        this.navObj = doc.layers["folder"+this.id];
        this.iconImg = this.navObj.document.images["folderIcon"+this.id];
        this.nodeImg = this.navObj.document.images["nodeIcon"+this.id];
		this.folderImg = this.navObj.document.images["folderImg"+this.id];
        doc.yPos = doc.yPos + this.navObj.clip.height;
    }
}

function outputFolderLink() {
    if(this.hreference) {
        doc.write("<A HREF='" + this.hreference + "' TARGET=MAIN")

        if(browserVersion > 0) {
            doc.write("onClick='JavaScript: clickOnFolder("+this.id+")'")
        }
        doc.write(">")
    }
    else {
        doc.write("<A>")
    }
}


function addChild(childNode) {
    this.children[this.nChildren] = childNode;
    this.nChildren++;
    return(childNode);
}

function folderSubEntries() {
    var i = 0;
    var se = this.nChildren;

    for(i = 0; i < this.nChildren; i++) {
        if(this.children[i].children) //is a folder
            se = se + this.children[i].subEntries();
    }

    return(se)
}


// Constructor
function Item(itemDescription, hreference, itemLink, itemImg, itemKey, menuID, parentIndex, nowIndex, lastIndex)  {

    // constant data
	this.parentIndex = parentIndex;
    this.desc = itemDescription
    this.link = itemLink
    this.hreference = hreference;
    this.id = -1;     //initialized in initalize()
    this.key = itemKey;
    this.navObj = 0;  //initialized in render()
    this.iconImg = 0; //initialized in render()
    this.iconSrc = itemImg;
	this.menuID = menuID;
	this.isSelected = false;

	this.isFolder = false;

	this.nowIndex = nowIndex;
	this.lastIndex = lastIndex;

    // methods
    this.initialize = initializeItem ;
    this.createIndex = createEntryIndex;
    this.hide = hideItem;

    this.display = display;

    this.renderOb = drawItem;

    this.totalHeight = totalHeight;

}

function hideItem() {
    if(browserVersion == 1) {
        if(this.navObj.style.display == "none")
            return;
        this.navObj.style.display = "none"
    }
    else {
        if(this.navObj.visibility == "hiden")
            return;
        this.navObj.visibility = "hiden";
    }
}


// 초기화 아이템 //
function initializeItem(level, lastNode, leftSide) {
    this.createIndex();

    if(level > 0) {
        if(lastNode) { //the last 'brother' in the children array
            this.renderOb(leftSide + "")
            leftSide = leftSide + ""
        }
        else {
            this.renderOb(leftSide + "")
            leftSide = leftSide + ""
        }
    }
    else {
        this.renderOb("")
	}

}

// 아이템 생성 //
function drawItem(leftSide) {
	if(browserVersion == 2)
		doc.write("<LAYER ID='item" + this.id + "' TOP=" + doc.yPos + " VISIBILITY=hiden>");

	if (this.key == 'Node')
	{
		doc.write("<TABLE width='166' style='margin:0 0 0 7'");
	}
	else
	{
		doc.write("<TABLE width='166' style='margin:0 0 0 7'");
	}

    if(browserVersion == 1)
		doc.write(" ID='item" + this.id + "' STYLE='position:block;'");

	doc.write(" BORDER=0 CELLSPACING=0 CELLPADDING=0>");

	if (this.key == 'Node'){
		doc.write("<tr><td colspan='3' class='leftmenu_line'></td></tr>");
	}

	if(this.nowIndex == 0) {
		doc.write("<tr><td><img src='/resource/images/left_box_t.gif'></td></tr>");
	}

	if (this.key == 'Node')
	{
		doc.write("<TR onclick=clickOnMenuID('"+this.menuID+"')><TD width='151' CLASS='leftmenu2dep'>");
	} else
	{
		doc.write("<TR onclick=clickOnMenuID('"+this.menuID+"')><TD CLASS='leftmenu3dep'>");
	}

	if(this.link != "") {
		//doc.write("<A HREF=" + this.link + ">");
		var menu_link = "parent.topFrame.makeIFrameMenu('" + this.menuID + "[" + this.desc + "]', " +
							"'" + this.desc + "', " +
							"'" + "/iFrame?Class=" + this.hreference + "', " +
							+ this.parentIndex + ", " +
							"'" + comForm.BIG_CD.value + "')";
		doc.write("<A HREF='#' onClick=\"" + menu_link + "\">");

	}

	if (this.key == 'Node')
	{
		doc.write("<IMG ID='itemIcon"+this.id+"' ");
		doc.write("SRC='"+this.iconSrc+"' BORDER=0 class='leftmenu_ball01'>");
	}
	else
	{
		doc.write("<IMG ALIGN='absmiddle' ID='itemIcon"+this.id+"' ");
		doc.write("SRC='"+this.iconSrc+"' BORDER=0 class='leftmenu_ball02'>");
	}

	if(this.link != "")
		doc.write("</A>");

    if(USETEXTLINKS) {
        if(this.link != "") {
			var menu_link = "parent.topFrame.makeIFrameMenu('" + this.menuID + "[" + this.desc + "]', " +
							"'" + this.desc + "', " +
							"'" + "/iFrame?Class=" + this.hreference + "', " +
							+ this.parentIndex + ", " +
							"'" + comForm.BIG_CD.value + "')";
            doc.write("<A HREF=\"#\" onClick=\"" + menu_link + "\">" + this.desc + "</A>");

		}
        else {
            doc.write(this.desc);
		}
    }
    else {
        doc.write(this.desc);
    }

	doc.write("</TD></TR>");

	if( this.lastIndex != -1 && (this.nowIndex == this.lastIndex) ) {
		doc.write("<tr> <td><img src='/resource/images/left_box_b.gif'></td></tr>");
		doc.write("<TR height='6'><TD></TD></TR>");
	}

	doc.write("</TABLE>");

    if(browserVersion == 2)
        doc.write("</layer>");

    if(browserVersion == 1) {
        this.navObj = doc.all["item"+this.id]
        this.iconImg = doc.all["itemIcon"+this.id]
    }
    else if(browserVersion == 2) {
        this.navObj = doc.layers["item"+this.id];
        this.iconImg = this.navObj.document.images["itemIcon"+this.id];
        doc.yPos = doc.yPos+this.navObj.clip.height;
    }
}

// Methods common to both objects (pseudo-inheritance)

function display() {
    if(browserVersion == 1)
        this.navObj.style.display = "block";
    else
        this.navObj.visibility = "show";
}

function createEntryIndex() {
    this.id = nEntries;
    indexOfEntries[nEntries] = this;
    nEntries++;
}


// total height of subEntries open

function totalHeight() { //used with browserVersion == 2

    var h = this.navObj.clip.height;
    var i = 0;

    if(this.isOpen) { // is a folder and _is_ open
        for(i = 0 ; i < this.nChildren; i++)
            h = h + this.children[i].totalHeight();
    }
    return h
}


// Events
function clickOnFolder(folderId) {
    var clicked = indexOfEntries[folderId];

    if(!clicked.isOpen)
        clickOnNode(folderId);

    if(clicked.isSelected) {
        return;
	}
}

function clickOnNode(folderId) {

    var clickedFolder = 0;
    var rootFolder = 0;
    var state = 0;
    var rootState = 0;

    rootFolder = indexOfEntries[0];
    clickedFolder = indexOfEntries[folderId];

    state = clickedFolder.isOpen;
    rootState = rootFolder.isOpen;

	curkey = clickedFolder.key;

	for(var i = 1; i < indexOfEntries.length; i++) {
		var curFolder = indexOfEntries[i];
		if(curFolder.isFolder) {
			curFolder.setState(false);
		}
	}

	if (mspr == "0") {
		clickedFolder.setState(!state); //open<->close
	} else {
		if (clickedFolder.key == "SubFolder") {
			clickedFolder.setState(!state); //open<->close
		} else {
			rootFolder.setState(0);
			rootFolder.setState(1);
			clickedFolder.setState(1); //open<->close
		}
	}
}

function reClickOnNode(folderId) {

	var clickedFolder = 0;
    var rootFolder = 0;
    var state = 0;
    var rootState = 0;

    rootFolder = indexOfEntries[0];
    clickedFolder = indexOfEntries[folderId];

	if(clickedFolder == null || clickedFolder == 'undefined')
		return;

    state = clickedFolder.isOpen;
    rootState = rootFolder.isOpen;

	curkey = clickedFolder.key;

	for(var i = 1; i < indexOfEntries.length; i++) {
		var curFolder = indexOfEntries[i];
		if(curFolder.isFolder) {
			curFolder.setState(false);
		}
	}

	if (mspr == "0") {
		clickedFolder.setState(!state); //open<->close
	} else {
		if (clickedFolder.key == "SubFolder") {
			clickedFolder.setState(!state); //open<->close
		} else {
			rootFolder.setState(0);
			rootFolder.setState(1);
			clickedFolder.setState(1); //open<->close
		}
	}
}
function clickOnNode2(folderId) {

    var clickedFolder = 0;
    var rootFolder = 0;
    var state = 0;
    var rootState = 0;

    rootFolder = indexOfEntries[0];
    clickedFolder = indexOfEntries[folderId];
    state = clickedFolder.isOpen;
    rootState = rootFolder.isOpen;

	//clickedFolder.setState(!state); //open<->close
	curkey = clickedFolder.key;

	if (mspr == "0") {
		clickedFolder.setState(!state); //open<->close
	} else {
		if (clickedFolder.key == "SubFolder") {
			clickedFolder.setState(!state); //open<->close
		} else {
			rootFolder.setState(0);
			rootFolder.setState(1);
			clickedFolder.setState(1); //open<->close
		}
	}
}

function initNode(folderId)
{
    var clickedFolder = 0;
    var rootFolder = 0;
    var state = 0;
    var rootState = 0;

    rootFolder = indexOfEntries[0];
    clickedFolder = indexOfEntries[folderId];
    state = clickedFolder.isOpen;
    rootState = rootFolder.isOpen;

	//clickedFolder.setState(!state); //open<->close
	curkey = clickedFolder.key;

	if (mspr == "0") {
		clickedFolder.setState(!state); //open<->close
	} else {
		if (clickedFolder.key == "SubFolder") {
			clickedFolder.setState(!state); //open<->close
		} else {
			rootFolder.setState(0);
			rootFolder.setState(1);
			clickedFolder.setState(1); //open<->close
		}
	}
}

function initializeDocument() {

    if(doc.all)
        browserVersion = 1; //IE4
    else if(doc.layers)
        browserVersion = 2; //NS4
    else
        browserVersion = 0; //other

    RootTree.initialize(0, 1, "");
    RootTree.display();

    if(browserVersion > 0) {
        //doc.write("<LAYER TOP="+indexOfEntries[nEntries-1].navObj.top+">&nbsp;</LAYER>");

		if (mspr == "0") {
			//close the whole tree
			initNode(0);
			//clickOnNode(0);
			//open the root folder
			initNode(0);
			//clickOnNode(0);
			//clickOnNode(1);
		} else {
			clickOnNode(0);
		}
    }

	if (this.selectedFolder > 0)
	{
		clickOnNode(this.selectedFolder);
	}
}

function initLink()
{
	if (this.selectedFolder > 0)
	{
		clickOnNode(this.selectedFolder);
	}

	// 선택된 폴더 지정 //
	if (this.selectedFolder)
	{
		selectedFolder = this.id;
	}

	// 초기 실행될 페이지 설정 //
	if (this.selectedLink != '')
	{
		parent.main.location.href = this.selectedLink;
	}

	doc.write(" <TABLE width='166' border='0' cellspacing='0' cellpadding='0' style='margin:0 0 0 7'>");
	doc.write("<tr><td colspan='3' class='leftmenu_line'></td></tr></TABLE>");
}

// Auxiliary Functions for Folder-Treee backward compatibility
function gFldr(description, hreference, folderOpenImg, folderCloseImg, folderKey, nowIndex, lastIndex) {
    folder = new Folder(description, hreference, folderOpenImg, folderCloseImg, folderKey, nowIndex, lastIndex);
    return(folder);
}

function gLnk(parent, target, description, linkData, itemImg, itemKey, menuID, nowIndex, lastIndex) {

    fullLink = ""
    if(target == 0) {
        if(linkData != "")
            fullLink = "'"+linkData+"' TARGET=main";
        else
            fullLink = "";
    }
    else if(target == 1) {
        if(linkData != "")
            fullLink = "'"+linkData+"' TARGET=\"top\"";
        else
            fullLink = "";
    }
	else if(target == 2) {
        if(linkData != "")
            fullLink = "'"+linkData+"' TARGET=\"_blank\"";
        else
            fullLink = "";
    }
	else if (target == 3)
	{
		if(linkData != "")
            fullLink = "'/iFrame?Class="+linkData+"' TARGET=\"main\"";
        else
            fullLink = "";
	}
	else if (target == 4)
	{
		if(linkData != "")
            fullLink = "'/elms/xml/com/help/"+linkData+".html' TARGET=\"main\"";
        else
            fullLink = "";
	}
    else { // target == 2
        if(linkData != "")
            fullLink = "'http://"+linkData+"' TARGET=main";
        else
            fullLink = "";
    }
    linkItem = new Item(description, linkData, fullLink, itemImg, itemKey, menuID, parent, nowIndex, lastIndex)
    return linkItem
}

function insFldr(parentFolder, childFolder) {
    return(parentFolder.addChild(childFolder));
}

function insDoc(parentFolder, document) {
    parentFolder.addChild(document);
}

